﻿// Silver.Globe, version 0.11 for Silverlight 1.1 Alpha
// Copyright © Florian Krüsch (xaml-kru.com)
// xaml-kru.com/silverglobe
// This source is subject to the Microsoft Public License (Ms-PL).
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx.
// All other rights reserved.

using System;
using System.Windows.Controls;
using System.Collections.Generic;
using SilverGlobe.Data;
using SilverGlobe;

namespace SilverglobeSample
{
    public partial class Page : Canvas
    {
        public Page()
        {
            InitializeComponent();

            _silverGlobe.SetLocations(new List<Location>
            {
                             // location name & coordinates
                new Location("Kuala Lumpur", new GeoPosition(3.13, 101.7), 
                             // location data                             
                             new EventData("Teched SEA", "August 11-14, 2008", "../images/events/logo1.jpg")), 
               
                new Location("Los Angeles", new GeoPosition(34, -118),
                             new EventData("PDC '08", "October 27-30, 2008", "../images/events/logo2.jpg")),

                new Location("Las Vegas", new GeoPosition(36.17, -115.13),
                             new EventData("MIX'08", "March 5-7, 2008", "../images/events/logo3.jpg")),

                new Location("New York", new GeoPosition(40.72, -74),
                             new EventData("VSLive! NY", "March 5-7, 2008", "../images/events/logo4.jpg")),

                new Location("Barcelona", new GeoPosition(41, 2),
                             new EventData("TechEd Europe", "2008 (tbd)", "../images/events/logo5.jpg")),
            }); 
            
            _silverGlobe.LocationMouseOver += SilverGlobe_LocationMouseOver;

            _silverGlobe.LocationMouseOut += SilverGlobe_LocationMouseOut;

            _silverGlobe.LocationSelected += SilverGlobe_LocationSelected;

            _silverGlobe.DragRotate += SilverGlobe_DragRotate;
        }

        private void SilverGlobe_DragRotate(object sender, EventArgs e)
        {
            _eventInfo.Hide();
        }

        private void SilverGlobe_LocationMouseOut(object sender, LocationEventArgs e)
        {
            _locationInfo.Hide();
        }

        private void SilverGlobe_LocationMouseOver(object sender, LocationEventArgs e)
        {
            Location loc = e.Location;
            _locationInfo.Show(loc);
        }

        private void SilverGlobe_LocationSelected(object sender, LocationEventArgs e)
        {
            Location loc = e.Location;
            EventData eventData = loc.Data as EventData;

            if (eventData != null)
            {
                _eventInfo.Show(eventData);
            }
        }
    }
}
